<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/25 0025
 * Time: 15:25
 */

namespace app\home\controller;


use app\model\model\Ad;
use app\model\model\Bujian;
use app\model\model\Bujian_type;
use app\model\model\Seo;
use think\Request;

class Tedian extends Base
{
//实例化
    protected $_Seo;
    protected $_Ad;
    protected $bujian;
    protected $bujiantype;

    public function __construct(Request $request = null){
        parent::__construct($request);
        $this->_Ad = new Ad();
        $this->_Seo = new Seo();
        $this->bujian = new Bujian();
        $this->bujiantype = new Bujian_type();
    }
    public function index(){
        //SEO
        $seo = $this->_Seo->getOne(['id'=>1]);
        $this->assign('seo',$seo);
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>28,'flag'=>1]);
        $this->assign('banner',$banner);
        $list = $this->bujian->getListSelect(['flag'=>1],true);
        foreach ($list as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
        }
        //分类
        $type = $this->bujiantype->getListSelect(true);
        $this->assign('type',$type);
        $this->assign('list',$list);
        $index = $this->bujiantype->getOne(3);
        $this->assign('index',$index);
        return $this->fetch();
    }
    public function getListBytype(){
        if(input('type')){
            $list = $this->bujian->getListSelect(['type_id'=>input('type'),'flag'=>1],true);
        }else{
            $list = $this->bujian->getListSelect(['flag'=>1],true);
        }

        return json_echo_msg(200,'chenggong',$list);
    }
    public function view(){
        //SEO
        $seo = $this->_Seo->getOne(['id'=>1]);
        $this->assign('seo',$seo);


        $id = input('name');
        $data = $this->bujian->getOne($id);
        $this->assign('data',$data);
        return $this->fetch();
    }
}